package thread;

import javax.swing.plaf.TableHeaderUI;
import java.util.Scanner;

public class Demo15 {
    private volatile static int count = 0;
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(()->{
            while(count == 0){
                //为了避免出现内存可见性问题，可以增加sleep语句或者使用volatile修饰
                /*try {
                    Thread.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }*/
            }
            System.out.println("t1线程结束");
        });
        Thread t2 = new Thread(()->{
            Scanner in = new Scanner(System.in);
            System.out.print("count的值：");
            count = in.nextInt();
        });

        t1.start();
        t2.start();

        t1.join();
        t2.join();
    }
}
